<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.lgx.right.entity.User"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	User onlineUser = (User)request.getAttribute("onlineUser");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>赠送积分</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/jsp/member/head.jsp" />
	<script type="text/javascript">
		//保存信息
		function save(){
			$('#saveBtn').attr('disabled','disabled');
			var score = escape(escape($('#score').val()));                  //获取score 
			var card = escape(escape($('#card').val()));         	        //获取card值
			var remark = escape(escape($('#remark').val()));               	//获取remark值
			var paramName = "";
			
			if(isNum(card)==1){            //表示是数字
				if(moibleExits(card) == 1){   //符合手机号码规则，表示为手机号码
					paramName = "mobile";
				}else{
					paramName = "card.id";
				}
			
				var url = path +"/member/createSGRs.htm?userId="+${onlineUser.getId()}+"&card="+card+"&score="+score+"&remark="+remark+"&paramName="+paramName;
				$.ajax({
					  url:url,
					  success: function(data) {
						  if(data == "2"){
							  alertBox("赠送成功！");
							  window.location = path+"/member/presented.htm";   //成功跳回查看页面
						  }else if(data == "1"){
							  alertBox("赠送失败！");
						  }else if(data == "3"){
							  alertBox("日志记录失败");
						  }else{
							  alertBox("操作异常!请重新登录");
						  }
					  }
				});
			
			}else{
				alertBox("请输入 合法的接收人信息!");
			}
			
		}
		
		function moibleExits(tel){  
			if(/^1[3|4|5|8][0-9]\d{8}$/.test(tel)){ 
				return "1";								
			}else{
				return "0";
			}
		}
		
		function isNum(val){
			if(/^\d{12}$/){   //会员卡号必须有12位,但是不会超过12位
				return "1";
			}else{
				return "0";
			}
		}
		
		
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>赠送积分</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<div class="ri_main">
	<form id="form" method="post">
		<table width="100%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
			<td width="15%" align="right" bgcolor="#FFFFFF">剩余积分</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left">
		    	<label id="cardid" name="cardid" style="width:200px;">${onlineUser != null?onlineUser.card.score:'' }</label>
		    </td>
		  </tr>
		  <tr>
		  	<td width="15%" align="right" bgcolor="#FFFFFF">接收人手机或卡号</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <input id="card" name="card" style="width:200px;" />
		    </td>
		  </tr>
		  <tr>
		  	<td align="right" bgcolor="#FFFFFF">赠送积分</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<input id="score" name="score" style="width:200px;" />
		    </td>
		  </tr>
		  <tr>
		  	<td align="right" bgcolor="#FFFFFF">备注</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<textarea rows="10" id="remark" name="remark" style="width:500px;"></textarea>
		    </td>
		  </tr>
		  <tr>
		      <td bgcolor="#FFFFFF" colspan="2" style="text-align: center;">
		      	<input type="button" name="button" id="button" onclick="save()" value="保  存" />
		      </td>
		  </tr>
		</table>
	</form>
	</div>
	</div>
  </body>
</html>
